<?php
    /**
     *  This pipeline is called each time after something is inserted to database
     */
    function ecatalogue_post_insertion($flux) {
        
        // Article inserted
        if ($flux['args']['table'] == 'spip_articles') {
            $id_article = $flux['args']['id_objet'];
            $id_rubrique = $flux['data']['id_rubrique'];
            insert_product($id_article, $id_rubrique);
        }
        
        return $flux;
    }

    /**
     *  Inserts product with given $id_article if $id_rubrique is ecatalogue rubrique
     */
    function insert_product($id_article, $id_rubrique) {
        include_spip('classes/class.Ecatalogue');
        include_spip('classes/class.ProductModel');
        $catalogue = new Ecatalogue();
        $product_mdl = new ProductModel();
        if ($catalogue->IsEcatalogueRubrique($id_rubrique)) {
            $data['id_article'] = $id_article;
            $product_mdl->insert($data);
        }
    }
?>